package com.mxpio.erp.mes.controller;

import com.mxpio.erp.common.mes.entity.ManufactureWorkOrderTaskSn;
import com.mxpio.erp.common.mes.service.ManufactureWorkOrderTaskSnService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ManufactureWorkOrderTaskSnController", description = "生产订单-工单-工序任务sn接口")
@RestController
@RequestMapping("/erp/mes/mowo/task/sn/")
public class ManufactureWorkOrderTaskSnController {
	@Autowired
	private ManufactureWorkOrderTaskSnService service;

	@GetMapping("list")
	@Operation(summary = "生产订单-工单-工序任务sn列表", description = "获取生产订单-工单-工序任务sn列表", method = "GET")
	public Result<List<ManufactureWorkOrderTaskSn>> list(Criteria criteria) throws UnsupportedEncodingException {
		List<ManufactureWorkOrderTaskSn> items = service.list(ManufactureWorkOrderTaskSn.class, criteria);
		return Result.OK(items);
	}
	
	@GetMapping("page")
	@Operation(summary = "生产订单-工单-工序任务sn列表", description = "获取生产订单-工单-工序任务sn列表", method = "GET")
	public Result<Page<ManufactureWorkOrderTaskSn>> page(Criteria criteria, Integer pageSize, Integer pageNo) throws UnsupportedEncodingException {
		Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<ManufactureWorkOrderTaskSn> items = service.listPage(ManufactureWorkOrderTaskSn.class, page, criteria);
		return Result.OK(items);
	}
	
	@GetMapping("list/{taskCode}")
	@Operation(summary = "根据taskCode获取生产订单-工单-工序任务sn", description = "根据taskCode获取生产订单-工单-工序任务sn", method = "GET")
	public Result<ManufactureWorkOrderTaskSn> getById(@PathVariable(name = "taskCode", required = true) String taskCode) {
		ManufactureWorkOrderTaskSn item = service.getById(ManufactureWorkOrderTaskSn.class, taskCode);
		return Result.OK(item);
	}


}
